package com.components.project

import android.content.Intent
import android.widget.Toast
import androidx.viewpager.widget.ViewPager
import com.components.base.view.BottomNavigationBar
import com.components.project.ui.activity.SpanActivity
import com.components.project.ui.base.ProjectBaseActivity
import com.components.project.ui.fragment.CooperationFragment
import com.components.project.ui.fragment.FunctionFragment
import com.components.project.ui.fragment.HomeFragment
import com.components.project.ui.fragment.UserCenterFragment

/**
 * @Author LuoKun
 * @Des
 */
class MainActivity : ProjectBaseActivity() {

    private lateinit var bottomNavigationBar: BottomNavigationBar
    private lateinit var viewPager: ViewPager

    override fun layoutId(): Int {
        return R.layout.activity_main
    }

    override fun initView() {
        viewPager = findViewById(R.id.viewPager)
        bottomNavigationBar = findViewById(R.id.bottomNavigationBar)
        bottomNavigationBar.attachViewPager(
            supportFragmentManager,
            viewPager,
            listOf(
                HomeFragment(),
                FunctionFragment(),
                CooperationFragment(),
                UserCenterFragment()
            )
        )
        bottomNavigationBar.setOnItemSelectedListener { item, position ->
            if (position == 2) {
                startActivity(Intent(this, SpanActivity::class.java))
            }
            false
        }
    }

    override fun initData() {

    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == RESULT_OK) {
            if (requestCode == ConstantManage.SCAN_QR_CODE) {
                Toast.makeText(
                    this,
                    data?.getStringExtra(com.components.zxing.ConstantManage.CODE_CONTENT)
                        .toString(),
                    Toast.LENGTH_SHORT
                ).show()
            }
        }
    }

}